<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>新增任务</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
        <script type="text/javascript" src="/webapp/js/common/metadata.js"></script>
	</head>
	<body>
		<div class="easyui-container-fluid">
			<div class="easyui-panel" style="border: none;">
              <div id="nav" class="nav"></div>
              <div class="easyui-panel" style="border:none;">
              	<form id="ff" name="model">
              		<div style="margin-bottom:20px;">
                        <label class="item-label"><span class="item-required">*</span>任务名：</label>
                        <input type="text" class="easyui-textbox " name="missionName"   data-options="required:true"/>
                        <label class="item-label"><span class="item-required">*</span>品类：</label>
                       <select class="easyui-combobox" id="categorySelect" name="categoryCode" style="width:128px;" required="required" >
                       </select>
                        <label class="item-label">确认字段</label>
                        <select id="cmField" class="easyui-combobox" style="width:174px;" name="cmField" data-options="multiple:true" required="required"></select>
                        <label class="item-label">截止时间：</label>
                        <input type="text" id="reportEndDate" class="easyui-datebox" data-options="formatter:dateFormatter,parser:dateParser" name="endTime" required="required"/>
                        <label class="item-label"><span class="item-required">*</span>总组数：</label>
                        <input type="text" class="easyui-numberspinner " name="groups" value="3" style="width:120px;" data-options="required:true"/>
                    </div>
              		<div style="margin-bottom:20px;">
              			<label class="item-label">原因：</label>
              			<input type="text" class="easyui-textbox" name="remarks" data-options="multiline:true" style="width:1159px;min-height:60px"/>
                    </div>
                </form>
                <div style="margin-bottom:20px;">
                    <label class="item-label">销售数据条件</label>
                    <form id="sdSql">
                        <div id="sdwrap-grup" style="margin-left: 90px;">
                            <div class="bkCss" id="sdwrap-grup1" style="border: 1px solid #5ffffd; ">
                                <div>
                                    <input id="sdandOr1" name ="sdandOr1" class="easyui-switchbutton " checked style="width:80px;height:30px; padding: 20px" onText="装饰" offText="作用"  >
                                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" style="width:120px;margin-left: 350px" onclick="sdAddColumn('sdwrap-ul1')">添加新列</a>
                                    <!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" style="width:120px" onclick="sdAddGroup()">添加新组</a>-->
                                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" style="width:120px" onclick="sdreGroup('sdwrap-grup1')">remove</a>
                                </div>
                                <div  id="sdwrap-ul1">
                                    <div id="sdwrap-column">
                                        <input type="text" name="sdpropCode1" id="sdpropCode1" class="easyui-combobox" style="width:200px; margin-left: 50px" data-options="panelHeight:'auto'" />
                                        <input type="text" name="sdcomparator1" id="sdcomparator1" class="easyui-combobox" style="width: 180px;margin-left: 100px" data-options="panelHeight:'auto'" prompt="比较符"/>
                                        <div style="display: inline-block;margin-left: 50px" id="sdmetadatavalue1">
                                        </div>
                                        <a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;'data-options="iconCls:'icon-cancel'" onclick='rmColumn("wrap-column")'></a>&nbsp;&nbsp;
                                    </div>
                                </div>

                            </div>
                        </div>
                    </form>
                </div>
                <div style="margin-bottom:20px; height: 80%; ">
                    <label class="item-label">型号条件:</label>
                    <form id="sql">
                        <div id="wrap-grup" style="margin-left: 90px;">
                            <div class="bkCss" id="wrap-grup1" style="border: 1px solid #5ffffd; ">
                                <div>
                                    <input id="andOr1" name ="andOr1" class="easyui-switchbutton " checked style="width:80px;height:30px; padding: 20px" onText="and" offText="or"  >
                                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" style="width:120px;margin-left: 250px" onclick="addColumn('wrap-ul1')">添加新列</a>
                                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" style="width:120px" onclick="addGroup()">添加新组</a>
                                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" style="width:120px" onclick="reGroup('wrap-grup1')">remove</a>
                                </div>
                                <div  id="wrap-ul1">
                                    <div id="wrap-column">
                                        <input type="text" name="propCode1" id="propCode1" class="easyui-combobox" style="width:200px; margin-left: 50px" data-options="panelHeight:'auto'" />
                                        <input type="text" name="comparator1" id="comparator1" class="easyui-combobox" style="width: 180px;margin-left: 100px" data-options="panelHeight:'auto'" prompt="比较符"/>
                                        <div style="display: inline-block;margin-left: 50px" id="metadatavalue1">
                                        </div>
                                        <a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;'data-options="iconCls:'icon-cancel'" onclick='rmColumn("wrap-column")'></a>&nbsp;&nbsp;
                                    </div>
                                </div>

                            </div>
                        </div>
                    </form>
                </div>
                <div style="margin-bottom:20px;margin-left:100px;">
                     <a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">保存</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancel()" style="width:80px">取消</a>
                </div>
              </div>
            </div>
        </div>
	</body>
  <script type="text/javascript">
      var criterias="";
      var groupId=1;
      var ulId=1;
      var upId=1;
      var sdgroupId=1;
      var sdulId=1;
      var sdupId=1;
      var id=getQueryParameter("id");
      $(function(){
          setNav();
          initsaSelect("sdpropCode1","sdmetadatavalue1","sdpropValue1");
          initUserCategorySelect("categorySelect",function (code) {
              initModelSearchSelect("cmField",null,code);
              initModelSearchSelect1("propCode1","metadatavalue1",code);
          });

          $("#comparator1").combobox({
              data:[
                  {text:"=",value:"EQUAL"},
                  {text:">",value:"GREAT"},
                  {text:">=",value:"GREAT_EQUAL"},
                  {text:"<",value:"LITTLE"},
                  {text:"<=",value:"LITTLE_EQUAL"},
                  {text:"<>",value:"NOT_EQUAL"},
                  {text:"包含",value:"CONTAIN"}]
          });
          $("#sdcomparator1").combobox({
              data:[
                  {text:"=",value:"EQUAL"},
                  {text:">=",value:"GREAT_EQUAL"},
                  {text:"<=",value:"LITTLE_EQUAL"},
                  {text:"包含",value:"CONTAIN"}]
          });
      });
      function submitForm(){
          $("#ff").form("submit",{
              onSubmit:function(){
                  var valid = $(this).form("enableValidation").form("validate");
                  if(valid){
                      var data = getFormData(document.getElementById("ff"));
                      var cmField = data.cmField;
                      if(!Array.isArray(cmField)){
                          data.cmField = [cmField];
                      }
                      if(!sdSetPropGroup(data)){
                          return;
                      }
                      setPropGroup(data);
                      $.ajax({
                          url:config.url+"/modelConfirm",
                          type:"POST",
                          data:JSON.stringify(data),
                          dataType:'json',
                          contentType:'application/json;charset=UTF-8',
                          beforeSend:function(){
                              window.parent.window.load();
                          },
                          complete:function(){
                              window.parent.window.disLoad();
                          },
                          xhrFields:{withCredentials:true},
                          success:function(data){
                              $.messager.alert("提示", "操作成功", "info", function () {
                                  window.parent.closeCurrentTab(true);
                              });

                          },
                          error:function(XMLHttpRequest,textStatus,thrown){
                              $.messager.alert("提示","操作失败","error");
                          }
                      });
                      return false;
                  }
                  return false;
              }
          })
      }
      function dateFormatter(date) {
          // console.log("date:",date);
          var y = date.getFullYear();
          var m = date.getMonth()+1;
          if(m<10){
              m="0"+m;
          }
          var d = date.getDate();
          if(d<10){
              d="0"+d;
          }
          return y+'-'+m+'-'+d;
      }
      function dateParser(date) {

      }
      function cancel(){
          window.parent.closeCurrentTab();
          // window.location.href="/webapp/pages/product/exclude/list.html";
      }

        //添加行
      function addColumn(id) {
          ulId=ulId+1;
          var inner = "<div id=\"wrap-column"+ulId+"\">\n"+
              "            <input type=\"text\" name='propCode1'id='propCode"+ulId+"' class=\"easyui-combobox\" style=\"width:200px; margin-left: 50px\" data-options=\"panelHeight:'auto'\" />\n" +
              "            <input type=\"text\" name='comparator1' id='comparator"+ulId+"' class=\"easyui-combobox comparator\" style=\"width: 180px;margin-left: 100px\" data-options=\"panelHeight:'auto'\" prompt=\"比较符\"/>\n" +
              "            <div style=\"display: inline-block;margin-left: 50px\" id='metadatavalue"+ulId+"' >\n" +
              "            </div><a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;'data-options=\"iconCls:'icon-cancel'\" onclick=\"rmColumn('wrap-column"+ulId+"')\"></a>&nbsp;&nbsp;\n" +
              "            </div>" +
              "        </div>\n"

          $(inner).appendTo("#"+id);
          $.parser.parse($("#propCode"+ulId).parent());
          var categoryCode = getFormData(document.getElementById("ff")).categoryCode;
          initModelSearchSelect1("propCode"+ulId+"","metadatavalue"+ulId+"",categoryCode);
          $("#comparator"+ulId).combobox({
              data:[
                  {text:"=",value:"EQUAL"},
                  {text:">",value:"GREAT"},
                  {text:">=",value:"GREAT_EQUAL"},
                  {text:"<",value:"LITTLE"},
                  {text:"<=",value:"LITTLE_EQUAL"},
                  {text:"<>",value:"NOT_EQUAL"},
                  {text:"包含",value:"CONTAIN"}]
          });
      }
      function addGroup() {
          groupId=groupId+1;
          ulId=ulId+1;
          var inner = "<div class=\"bkCss\" id=\"wrap-grup"+groupId+"\" style=\"border: 1px solid #5ffffd;\">\n" +
              "        <div>\n" +
              "            <input id='andOr"+groupId+"' name='andOr"+groupId+"' class=\"easyui-switchbutton \" checked style=\"width:80px;height:30px; padding: 20px\" onText=\"and\" offText=\"or\"  >\n" +
              "            <a href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-edit'\" style=\"width:120px;margin-left: 250px\"" +
              " onclick=\"addColumn('wrap-ul"+groupId+"')\">添加新列</a>\n" +
              "            <a href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-add'\" style=\"width:120px\" " +
              "onclick='addGroup()'>添加新组</a>\n" +
              "            <a href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-remove'\" style=\"width:120px\" onclick=\"reGroup('wrap-grup"+groupId+"')\">remove</a>\n" +
              "        </div>\n" +
              "        <div  id='wrap-ul"+groupId+"'>" +
              "<div id=\"wrap-column"+ulId+"\">"+
              "            <input type=\"text\" name='propCode1' id='propCode"+ulId+"' class=\"easyui-combobox\" style=\"width:200px; margin-left: 50px\" data-options=\"panelHeight:'auto'\" />\n" +
              "            <input type=\"text\" name='comparator1'id='comparator"+ulId+"' class=\"easyui-combobox comparator\" style=\"width: 180px;margin-left: 100px\" data-options=\"panelHeight:'auto'\" prompt=\"比较符\"/>\n" +
              "            <div style=\"display: inline-block;margin-left: 50px\" id='metadatavalue"+ulId+"' >\n" +
              "            </div><a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;'data-options=\"iconCls:'icon-cancel'\" onclick=\"rmColumn('wrap-column"+ulId+"')\"></a>&nbsp;&nbsp;\n" +
              "            </div>\n" +
              "        </div>\n" +
              "    </div>"

          $(inner).appendTo("#wrap-grup");
          $.parser.parse($("#wrap-ul"+groupId).parent());
          var categoryCode = getFormData(document.getElementById("ff")).categoryCode;
          initModelSearchSelect1("propCode"+ulId+"","metadatavalue"+ulId+"",categoryCode);
          $("#comparator"+ulId).combobox({
              data:[
                  {text:"=",value:"EQUAL"},
                  {text:">",value:"GREAT"},
                  {text:">=",value:"GREAT_EQUAL"},
                  {text:"<",value:"LITTLE"},
                  {text:"<=",value:"LITTLE_EQUAL"},
                  {text:"<>",value:"NOT_EQUAL"},
                  {text:"包含",value:"CONTAIN"}]
          });
      }
      function rmColumn(id) {
          $('#'+id).remove();
      }
      function reGroup(id) {
          $('#'+id).remove();
      }
      function spliceSql(id) {
          var add=0;
          var data = getFormData(document.getElementById("sql"));
          var criteria="";
          var subscript=0;//存下标
          for(var a=1;a<=groupId;a++){
              var ComplexQueryVO=[];
              var andOr="andOr"+a;
              var zss=$("#wrap-ul"+a).children().length//每个组的条件
              if(zss==0){
                  continue;
              }
              // console.log(data[andOr]);
              if(  data[andOr] == undefined){
                  var dh=0;
                  if(zss==1){
                      alert("OR的条件必须多个")
                      return;
                  }
                  //当前组是or
                  criteria=criteria+ "Criteria.orOperator(";
                  ComplexQueryVO.andOr ="OR";
                  for (var i=0;i<zss;i++){
                      var y=i+subscript;
                      var propCode=data.propCode1[y];
                      var comparator=data.comparator1[y];
                      var value=data.propValue1[y];
                      if(propCode != null &&propCode != ""
                          && comparator != null &&comparator != ""
                          &&value != null &&value != "" ){
                          if(dh==1){
                              criteria= criteria+","
                          }
                          if(Number(value)){
                              criteria= criteria+"Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"("+value+"))";
                          }else {
                              criteria= criteria+"Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"(\""+value+"\"))";
                          }
                      }
                      dh=1;
                  }
                  criteria=criteria+");";
              }else{
                  //当前组是and
                  if(add==1){
                      alert("add只允许存在一次");
                      return;
                  }
                  add=1;
                  criteria=criteria+"Criteria"
                  for (var i=0;i<zss;i++){
                      var y=i+subscript;
                      var propCode=data.propCode1[y];
                      var comparator=data.comparator1[y];
                      var value=data.propValue1[y];
                      if(propCode != null &&propCode != ""
                          && comparator != null &&comparator != ""
                          &&value != null &&value != "" ){
                          if(Number(value)){
                              criteria= criteria+".andOperator(Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"("+value+"))";
                          }else {
                              criteria= criteria+".andOperator(Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"(\""+value+"\"))";
                          }
                      }
                  }
                  criteria=criteria+"));";
              }
              subscript=subscript+zss;
          }
          criterias=criteria;
          $("#cq").window("close");
      }

      function initsaSelect(propCode,metadatawrapper,propValue){
          var data=[{"name":"-请选择-","code":""},{"name":"年份","code":"year"},{"name":"月份","code":"month"}];
          data.push({"name":"周度","code":"week"})
          data.push({"name":"报告类型","code":"reportType"})
          data.push({"name":"top榜单（量排序）","code":"top"})
          data.push({"name":"top榜单（额排序）","code":"topTotal"})
          $("#"+propCode).combobox({
              textField:"name",
              valueField:"code",
              panelHeight:"200px",
              data:data,
              onChange:function (newValue,oldValue) {
                  if("reportType"==newValue){
                      inner = "<select name='sdpropValue2' class=\"easyui-combobox\" style=\"width:174px;\" name=\"categoryCode\" data-options=\"multiple:true\">";
                      inner += "<option value=\"MONTH\">月报</option>\n" +
                          "                        <option value=\"WEEK\" >周报</option>\n" +
                          "                        <option value=\"ONLINE\" >电商(周)</option>\n" +
                          "                        <option value=\"ONLINE_M\">电商(月)</option>\n"+
                          "                        <option value=\"PDK_W\">拼抖快(周)</option>\n"+
                          "                        <option value=\"PDK_M\">拼抖快(月)</option>\n";
                      inner += "</select>"
                  }else{
                      //根据是否有值来决定是下拉框还是文本框
                      var inner = "";
                      var proValueName = propValue || "propValue1";
                      inner = "<input type='text' class='easyui-textbox' name='"+proValueName+"' style='width:200px' prompt='请输入值'/>"
                  }

                  $("#"+metadatawrapper).html(inner);
                  $.parser.parse($("#"+metadatawrapper));
              }
          });
      }


      //添加销售数据行
      function sdAddColumn(id) {
          sdulId=sdulId+1;
          var inner = "<div id=\"sdwrap-column"+sdulId+"\">\n"+
              "            <input type=\"text\" name='sdpropCode1'id='sdpropCode"+sdulId+"' class=\"easyui-combobox\" style=\"width:200px; margin-left: 50px\" data-options=\"panelHeight:'auto'\" />\n" +
              "            <input type=\"text\" name='sdcomparator1' id='sdcomparator"+sdulId+"' class=\"easyui-combobox comparator\" style=\"width: 180px;margin-left: 100px\" data-options=\"panelHeight:'auto'\" prompt=\"比较符\"/>\n" +
              "            <div style=\"display: inline-block;margin-left: 50px\" id='sdmetadatavalue"+sdulId+"' >\n" +
              "            </div><a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;'data-options=\"iconCls:'icon-cancel'\" onclick=\"sdrmColumn('sdwrap-column"+sdulId+"')\"></a>&nbsp;&nbsp;\n" +
              "            </div>" +
              "        </div>\n"

          $(inner).appendTo("#"+id);
          $.parser.parse($("#sdpropCode"+sdulId).parent());
          initsaSelect("sdpropCode"+sdulId+"","sdmetadatavalue"+sdulId+"","sdpropValue1");
          $("#sdcomparator"+sdulId).combobox({
              data:[
                  {text:"=",value:"EQUAL"},
                  // {text:">",value:"GREAT"},
                  {text:">=",value:"GREAT_EQUAL"},
                  // {text:"<",value:"LITTLE"},
                  {text:"<=",value:"LITTLE_EQUAL"},
                  // {text:"<>",value:"NOT_EQUAL"},
                  {text:"包含",value:"CONTAIN"}]
          });
      }
      function sdAddGroup() {
          sdgroupId=sdgroupId+1;
          sdulId=sdulId+1;
          var inner = "<div class=\"bkCss\" id=\"sdwrap-grup"+sdgroupId+"\" style=\"border: 1px solid #5ffffd;\">\n" +
              "        <div>\n" +
              "            <input id='sdandOr"+sdgroupId+"' name='sdandOr"+sdgroupId+"' class=\"easyui-switchbutton \" checked style=\"width:80px;height:30px; padding: 20px\" onText=\"and\" offText=\"or\"  >\n" +
              "            <a href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-edit'\" style=\"width:120px;margin-left: 250px\"" +
              " onclick=\"sdAddColumn('sdwrap-ul"+sdgroupId+"')\">添加新列</a>\n" +
              "            <a href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-add'\" style=\"width:120px\" " +
              "onclick='sdAddGroup()'>添加新组</a>\n" +
              "            <a href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-remove'\" style=\"width:120px\" onclick=\"sdreGroup('sdwrap-grup"+sdgroupId+"')\">remove</a>\n" +
              "        </div>\n" +
              "        <div  id='sdwrap-ul"+sdgroupId+"'>" +
              "<div id=\"sdwrap-column"+sdulId+"\">"+
              "            <input type=\"text\" name='sdpropCode1' id='sdpropCode"+sdulId+"' class=\"easyui-combobox\" style=\"width:200px; margin-left: 50px\" data-options=\"panelHeight:'auto'\" />\n" +
              "            <input type=\"text\" name='sdcomparator1'id='sdcomparator"+sdulId+"' class=\"easyui-combobox comparator\" style=\"width: 180px;margin-left: 100px\" data-options=\"panelHeight:'auto'\" prompt=\"比较符\"/>\n" +
              "            <div style=\"display: inline-block;margin-left: 50px\" id='sdmetadatavalue"+sdulId+"' >\n" +
              "            </div><a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;'data-options=\"iconCls:'icon-cancel'\" onclick=\"sdrmColumn('sdwrap-column"+sdulId+"')\"></a>&nbsp;&nbsp;\n" +
              "            </div>\n" +
              "        </div>\n" +
              "    </div>"

          $(inner).appendTo("#sdwrap-grup");
          $.parser.parse($("#sdwrap-ul"+sdgroupId).parent());
          initsaSelect("sdpropCode"+sdulId+"","sdmetadatavalue"+sdulId+"","sdpropValue1");
          $("#sdcomparator"+sdulId).combobox({
              data:[
                  {text:"=",value:"EQUAL"},
                  {text:">",value:"GREAT"},
                  {text:">=",value:"GREAT_EQUAL"},
                  {text:"<",value:"LITTLE"},
                  {text:"<=",value:"LITTLE_EQUAL"},
                  {text:"<>",value:"NOT_EQUAL"},
                  {text:"包含",value:"CONTAIN"}]
          });
      }
      function sdrmColumn(id) {
          $('#'+id).remove();
      }
      function sdreGroup(id) {
          $('#'+id).remove();
      }
      function sdSpliceSql(id) {
          var add=0;
          var data = getFormData(document.getElementById("adsql"));
          var criteria="";
          var subscript=0;//存下标
          for(var a=1;a<=groupId;a++){
              var ComplexQueryVO=[];
              var andOr="sdandOr"+a;
              var zss=$("#sdwrap-ul"+a).children().length//每个组的条件
              if(zss==0){
                  continue;
              }
              // console.log(data[andOr]);
              if(  data[andOr] == undefined){
                  var dh=0;
                  if(zss==1){
                      alert("OR的条件必须多个")
                      return;
                  }
                  //当前组是or
                  criteria=criteria+ "Criteria.orOperator(";
                  ComplexQueryVO.andOr ="OR";
                  for (var i=0;i<zss;i++){
                      var y=i+subscript;
                      var propCode=data.propCode1[y];
                      var comparator=data.comparator1[y];
                      var value=data.propValue1[y];
                      if(propCode != null &&propCode != ""
                          && comparator != null &&comparator != ""
                          &&value != null &&value != "" ){
                          if(dh==1){
                              criteria= criteria+","
                          }
                          if(Number(value)){
                              criteria= criteria+"Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"("+value+"))";
                          }else {
                              criteria= criteria+"Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"(\""+value+"\"))";
                          }
                      }
                      dh=1;
                  }
                  criteria=criteria+");";
              }else{
                  //当前组是and
                  if(add==1){
                      alert("add只允许存在一次");
                      return;
                  }
                  add=1;
                  criteria=criteria+"Criteria"
                  for (var i=0;i<zss;i++){
                      var y=i+subscript;
                      var propCode=data.propCode1[y];
                      var comparator=data.comparator1[y];
                      var value=data.propValue1[y];
                      if(propCode != null &&propCode != ""
                          && comparator != null &&comparator != ""
                          &&value != null &&value != "" ){
                          if(Number(value)){
                              criteria= criteria+".andOperator(Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"("+value+"))";
                          }else {
                              criteria= criteria+".andOperator(Criteria.where(\"properties\").elemMatch(Criteria.where(\"code\").is(\""+propCode+"\").and(\"value\")."+comparator+"(\""+value+"\"))";
                          }
                      }
                  }
                  criteria=criteria+"));";
              }
              subscript=subscript+zss;
          }
          criterias=criteria;
          $("#cq").window("close");
      }

      function setPropGroup(prom) {
          var data = getFormData(document.getElementById("sql"));
          var subscript=0;//存下标
          var ComplexQueryVOs = [];

          if( !data || !data.propValue1 ){
              return;
          }
          if((typeof data.propValue1=='object')&& data.propValue1.constructor==Array){
              for(var a=1;a<=groupId;a++){
                  var andOr="andOr"+a;
                  var zss=$("#wrap-ul"+a).children().length//每个组的条件
                  if(zss==0){
                      return;
                  }
                  var ComplexQueryVO={};
                  if(  data[andOr] == undefined){
                      ComplexQueryVO.andOr ="OR";
                  }else {
                      ComplexQueryVO.andOr ="AND";
                  }
                  var pcpVOs = [];
                  for (var i=0;i<zss;i++){
                      var y=i+subscript;
                      var propCode=data.propCode1[y];
                      var comparator=data.comparator1[y];

                      var value=data.propValue1[y];
                      if(propCode&&comparator&&value){
                          var prop ={};
                          prop.code = propCode;
                          prop.value = value;
                          var PcpVO = {};
                          PcpVO.prop = prop;
                          PcpVO.comparator = comparator;
                          pcpVOs.push(PcpVO);
                      }
                  }
                  subscript=subscript+zss;
                  ComplexQueryVO.pcpVO = pcpVOs;
                  ComplexQueryVOs.push(ComplexQueryVO);
              }
          }else{
              prom.properties = [{code:data.propCode1,comparator:data.comparator1,value:data.propValue1}];
              prom.comparator=data.comparator1;
          }

          prom.complexProperties = ComplexQueryVOs;
      }
      function sdSetPropGroup(prom) {
          var data = getFormData(document.getElementById("sdSql"));
          var subscript=0;//存下标
          var ComplexQueryVOs = [];
          if((typeof data.sdpropValue1=='object')&& data.sdpropValue1.constructor==Array){
              var sdpropCode1=[];
              var sdcomparator1=[];
              for (var i = 0; i < data.sdpropCode1.length; i++) {
                  if ( data.sdpropCode1[i] != "reportType") {
                      sdpropCode1.push(data.sdpropCode1[i]);
                      sdcomparator1.push(data.sdcomparator1[i]);
                  }
              }
              for(var a=1;a<=sdgroupId;a++){
                  var andOr="sdandOr"+a;
                  var zss=$("#sdwrap-ul"+a).children().length//每个组的条件
                  if(zss==0){
                      return;
                  }
                  var ComplexQueryVO={};
                  if(  data[andOr] == undefined){
                      ComplexQueryVO.andOr ="OR";
                  }else {
                      ComplexQueryVO.andOr ="AND";
                  }
                  var pcpVOs = [];
                  for (var i=0;i<zss;i++){
                      var y=i+subscript;
                      var propCode=sdpropCode1[y];
                      var comparator=sdcomparator1[y];

                      var value=data.sdpropValue1[y];
                      if(propCode&&comparator&&value){
                          var prop ={};
                          prop.code = propCode;
                          prop.value = value;
                          var PcpVO = {};
                          PcpVO.prop = prop;
                          PcpVO.comparator = comparator;
                          pcpVOs.push(PcpVO);
                      }
                  }
                  if(data.sdpropValue2){
                      var prop ={};
                      prop.code = "reportType";
                      prop.value = data.sdpropValue2;
                      var PcpVO = {};
                      PcpVO.prop = prop;
                      PcpVO.comparator = "CONTAIN";
                      pcpVOs.push(PcpVO);
                  }
                  subscript=subscript+zss;
                  ComplexQueryVO.pcpVO = pcpVOs;
                  ComplexQueryVOs.push(ComplexQueryVO);
              }
          }else{
              if(data.sdpropValue1 && data.sdpropCode1){
                  $.messager.alert("提示", "条件过于宽泛,不支持查询", "error");
                  return false;
              }
          }

          prom.sdCt = ComplexQueryVOs;
          return true;
      }
  </script>
</html>